from PySide6.QtCore import Signal, Slot, Qt
from PySide6.QtGui import QKeyEvent
from PySide6.QtWidgets import QWidget, QApplication


class AbstractKeyboard(QWidget):
    keyPressed = Signal(int, str)
    def __init__(self, parent=None):
        super().__init__(parent)
        self._name = ""

    @property
    def name(self):
        return self._name

    @name.setter
    def name(self, name):
        self._name = name

    @Slot(str)
    def update(self, text):
        pass

    @Slot(int, str)
    def onKeyPressed(self, key, value):
        print(f"key: {key}, Value: {value}")
        receiver = QApplication.focusWidget()
        if receiver is None:
            return

        keyPress = QKeyEvent(QKeyEvent.KeyPress, key, Qt.NoModifier, value)
        keyRelease = QKeyEvent(QKeyEvent.KeyRelease, key, Qt.NoModifier, value)

        QApplication.sendEvent(receiver, keyPress)
        QApplication.sendEvent(receiver, keyRelease)
